﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Windows.Forms;

namespace Save2openExcel2007
{
    public partial class Ribbon1 : OfficeRibbon
    {
        private libs lib = new libs();
        sLogin sLoginForm = new sLogin();
        public Ribbon1()
        {
            InitializeComponent();
        }

        private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
        {

        }

        private void sSave_Click(object sender, RibbonControlEventArgs e)
        {
            string post = lib.getPost();
            if (post == "-1")
            {
                sLoginForm.ShowDialog();
                post = lib.getPost();
            }
            if (post != "-1")
            {
                string upstat = lib.upload(post);
                if (upstat != "0")
                {
                    if (upstat == "2") lib.clearPost();
                    MessageBox.Show(lib.errMsg(upstat));
                }
            }
        }

        private void sOpen_Click(object sender, RibbonControlEventArgs e)
        {
            string post;
            post = lib.getPost();
            if (post == "-1")
            {
                sLoginForm.ShowDialog();
                post = sLoginForm.getPost();
            }
            if (post != "-1")
            {
                string fileinfo = lib.getFilelist(post);
                if (fileinfo.Length == 1)
                {
                    MessageBox.Show(lib.errMsg(fileinfo));
                }
                else
                {
                    sOpendoc openFrom = new sOpendoc(fileinfo);
                    openFrom.ShowDialog();
                    string selFile = openFrom.getSelF();
                    if (selFile != "")
                    {
                        string status = lib.getFile(lib.getPost(), selFile);
                        if (status == "-1") MessageBox.Show("打开文件失败，请重试");
                    }
                }
            }
        }

        private void sClear_Click(object sender, RibbonControlEventArgs e)
        {
            lib.clearPost();
        }

        private void sHelp_Click(object sender, RibbonControlEventArgs e)
        {
            System.Diagnostics.Process.Start(lib.esUrl + "/support");
        }

        private void sAbout_Click(object sender, RibbonControlEventArgs e)
        {
            sAbout about = new sAbout();
            about.Show();
        }
    }
}
